package demo1;

public class LeetCode153 {
    public int findMin1(int[] nums) {
        int n = nums.length - 1;
        int left = 0, right = n;
        while (left < right) {
            int mid = left + (right - left) / 2;
            if(nums[mid] > nums[n]) left = mid + 1;
            else right = mid;
        }
        return nums[left];
    }

    public int findMin(int[] nums) {
        int n = nums.length - 1;
        int left = 0, right = n;
        if (nums[left] < nums[right]) return nums[left];
        while (left < right) {
            int mid = left + (right - left) / 2;
            if(nums[mid] >= nums[0]) left = mid + 1;
            else right = mid;
        }
        return nums[left];
    }
}
